import React, { useEffect, useRef } from 'react'

export default function index() {
  let state = useRef(0)
  let btnRef = useRef(null)

  console.log(btnRef, 'btnRef')
  // 这里获取不到

  useEffect(() => {
    console.log(btnRef, 'btnRef')
    // 这里可以获取到
  }, [])

  useEffect(() => {
    console.log(state.current)
    // 监听不到
  }, [state.current])

  const add = () => {
    state.current += 1
    console.log(state.current) // 点击按钮会同步打印state的值
  }

  return (
    <div>
      <button onClick={add} ref={btnRef}>加一</button>
    </div>
  )
}
